/**
 * Project Name:九色鹿
 * File Name:NotifySmsAutoConfiguration.java
 * Package Name:com.fxp.project.sms.chuanglan.configuration
 * Date:2021年09月14日 10:57
 * Copyright (c) 2021, Jason.Wang All Rights Reserved.
 */
package com.fxp.project.sms.chuanglan.configuration;

import com.fxp.project.sms.chuanglan.config.NotificationProperties;
import com.fxp.project.sms.chuanglan.provider.NotifySmsProvider;
import com.fxp.project.sms.chuanglan.service.ISmsService;
import com.fxp.project.sms.chuanglan.service.impl.NotificationSmsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * ClassName:NotifySmsAutoConfiguration<br/>
 * Function: 通知短信配置<br/>
 * Date:2021年09月14日 10:57<br/>
 *
 * @author Jason.Wang
 * @version 1.0.0.0
 * @see
 * @since JDK 8
 */
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(prefix = "sms.chuanglan.notification", name = "app-id")
@EnableConfigurationProperties({NotificationProperties.class})
@Import({NotifySmsProvider.class})
public class NotifySmsAutoConfiguration {

    /**
     * 定义接口对象
     */
    private final NotifySmsProvider notifySmsProvider;
    @Autowired
    private NotificationProperties notificationProperties;

    /**
     * SmsServiceAutoConfiguration: 构建自动注入对象<br/>
     *
     * @param notifySmsProvider
     * @author Jason.Wang
     * @date 2021/9/13 17:53
     */
    public NotifySmsAutoConfiguration(NotifySmsProvider notifySmsProvider) {
        this.notifySmsProvider = notifySmsProvider;
    }

    /**
     * NotificationSmsServiceImpl: 创建实体对象<br/>
     *
     * @return
     * @author Jason.Wang
     * @date 2021/9/14 11:41
     */
    @Bean(name = "notificationSmsService")
    @ConditionalOnMissingBean(NotificationSmsServiceImpl.class)
    ISmsService NotificationSmsServiceImpl() {
        NotificationSmsServiceImpl.initInstance(notifySmsProvider.init(notificationProperties));
        return NotificationSmsServiceImpl.getInstance();
    }
}